#include <iostream>
#include <math.h>
#include "constants.h"

using namespace std;


//const double PI = 3.1415927;
//
//double aR = -10 ;
//double bR = 5 ;
//
//const int WIDTH = 256;
//const int HEIGHT = 256;
//
//double a[3] = {aR, -aR/2, -3* aR/2};
//double b[3] = {bR, bR/2, 2*bR};

void MarM(int width, int height, float *marM)
{
	for(int h = 0 ; h < height; h ++)
		for(int w = 0 ; w < width; w ++)
		{

			double sinThetaI = -1.0f + (w * 2.0f) / width;
			double sinThetaO = -1.0f + (h * 2.0f) / height;
			double thetaI = asin(sinThetaI) * 180 / PI;
			double thetaO = asin(sinThetaO) * 180 / PI;
			double thetaH = (thetaI + thetaO) / 2;
			
			for(int c = 0 ; c < 3; c++)
			{
				marM[ (h*height + w) * 4 + c] = 1.0 / (sqrt(2 * PI) * abs(b[c])) * exp(-(thetaH - a[c])*(thetaH - a[c])/2/ (b[c] * b[c]));
			}
			marM[(h*height + w) * 4 + 3] = cos((thetaO - thetaI)/2);
			//marM[(h*height + w) * 4 + 3] = 1;
		}
}

void TestTexture(float *marM)
{
	for(int h = 0 ; h < HEIGHT; h ++)
		for(int w = 0 ; w < WIDTH; w ++)
		{	
			for(int c = 0 ; c < 4; c++)
			{
				switch(c)			
				{
				case 0: marM[ (h*HEIGHT + w) * 4 + c] = 0;break;
				case 1: marM[ (h*HEIGHT + w) * 4 + c] = 255;break;
				case 2: marM[ (h*HEIGHT + w) * 4 + c] = 200;break;
				case 3: marM[ (h*HEIGHT + w) * 4 + c] = 10;break;
				}
			}
		}
}

